//
// Created by summerday on 2021/6/5.
//

#include "iostream"
#include "queue.h"
using namespace std;

void initQueue(SqQueue &q){
    q.rear = q.front = 0;
    q.size = 0;
}

bool enq(SqQueue &q, int x){
    if(full(q)){
        return false;
    }
    q.data[q.rear] = x;
    q.rear = (q.rear + 1) % MAX_SIZE; // 循环
    q.size ++;
    return true;
}

bool deq(SqQueue &q, int &x){
    if(empty(q)) {
        return false;
    }
    x = q.data[q.front];
    q.front = (q.front + 1) % MAX_SIZE;
    q.size --;
    return true;
}

// 指到一起 初始化 or size == 0
bool empty(SqQueue q){
    return q.rear == q.front;
}

bool full(SqQueue q){
    // 牺牲一个格子 or size == MAX_SIZE
    return (q.rear + 1) % MAX_SIZE == q.front;
}

bool getHead(SqQueue q, int &x){
    if(empty(q)){
        return false;
    }
    x = q.data[q.front];
    return true;
}

